/*AyflEomXWyqCHfdTxzWda1f37E6BmbYMFlQ4qgWlYuq3WYvveC97Qm1zYJR3TbDu*/
/*
 * @Author: Chendch
 * @Date: 2020-10-13 16:05:56
 * @LastEditors: Chendch
 * @LastEditTime: 2021-09-26 11:02:19
 */
//第三方依赖
import React, { Component, Fragment } from 'react';
import ReactDOM from 'react-dom';

//本地依赖
import { ajax, base, cacheTools, high, output, print, promptBox, toast, pageTo } from 'nc-lightapp-front';
import initTemplate from "./init/initTemplate";
import {queryLang, queryorg, updateOrgsgrid, delOrg, freezeSupplier, quickBatchUpdate} from "./dataManage";
import draw from "./render/renderDOM";
import {constProp, referUrls, Urls} from "./CONSTANCE";
import SupBrowseOrgDoc from '../component/SupBrowseOrgDoc'; //查看组织档案
import SupOrgBrowse from '../component/SupOrgBrowse'; //按组织查看
import QueryHasAssignOrg from '../component/QueryHasAssignOrg'; //已分配组织查询
import { onMainTableButtonClick, onMainTableOprButtonClick, setMainTablePageButton } from './events/SupMainTableBtnAction';
import confirmUtil from '../../../public/pubComponent/confirmUtil/confirmUtil';
import { getCurParam, showFormulaSetting,validateAddOrCopy } from '../utils/SupplierUtils';
import {onMainTableOperateDelClick} from "../utils/deleteSupplier";
import OrgSelect from '../assign/QuickAssign'; //组织选择（分配使用）
import {renderContentArea} from "./render/renderTableContent";
import { onAssociateCustSureClick, onAssociateCustCancelBtnClick, onAssociateCustPrompSureBtnClick, associateCustContent} from "../utils/AssociateCust";
import {createCustContent, onCreateCustSureBtnClick, onCreateCustCancelBtnClick, onAfterCreateCustClose} from "../utils/createCust";
require('./index.less');
import '../../../public/cssStyle/_button.less';
/**
 * 页面状态
 * @type {{BROWSE: string, EDIT: string}}
 */
const statusProp = {BROWSE:'browse',EDIT:'edit'};

export default class Supplier extends Component{
  constructor(props){
    super(props);
    props.use.search('supplierquery');
    props.use.form('cardsupbankacc','accbasinfo','netbankinfo',constProp.SUPFINANCE_CARD,constProp.SUPSTOCK_CARD,'createCust','associcust',constProp.SUP_BASE_CARD,'linkman',
         "linkmanRefer", "queryHasAssignOrg_supplier", "versionList_card", "versionCard");
    props.use.table('supplier_baseInfo');
    props.use.editTable('supaddress', "versionList");
    props.use.cardTable('suplinkman','supcountrytaxes','supbankacc','finance','purchase','bankaccsub');
    props.use.table('SubjectOrg');
    //多语对象
    this.Lang = {};
    this.inlt = null;
    //初始state
    this.state = {
      loadLang:false,
      envParam:undefined,/*初始参数*/
      indivOrg:undefined,
      pk_supplier:'',//选中行的主键
      billType:this.props.billType,
      forceRender: true
    };
    this.initLoad();
  }

  /*
  *  选中模式
  */
  handleChange(value) {
      this.setState({
          selectType: value
      });
  }

  initLoad = async() => {
    let langData = await queryLang.call(this);
    if(langData == "error") {
      toast({color: "danger", content: "多语加载失败!"});
      return ;
    }
    const {json, inlt} = langData;
    this.Lang = json;
    this.inlt = inlt
    initTemplate.call(this, this.props);
  }

   /**
     * 查看组织档案 弹出框内容
     * @returns {*}
     */
    browseOrgDocContent = ()=>{
        return(<SupBrowseOrgDoc {...Object.assign(this.props,{envParam:this.state.envParam},{Lang:this.Lang,inlt:this.inlt})} ref={(SupBrowseOrgDoc)=>{this.SupBrowseOrgDoc = SupBrowseOrgDoc;}}/>)
    }
    /**
     * 查看组织档案  弹窗关闭前 清空数据
     */
    onBeforeBrowseOrgDocDialogClose = (callback)=>{
        this.SupBrowseOrgDoc.clearHasAssignTableData(()=>{
            //清空表格数据
            this.props.table.setAllTableData('browse_org_supplier',{rows:[]});
            //清空查询区
            this.props.search.clearSearchArea('browse_org_supplierquery');
            callback && callback();
        })
    }

   /**
  * 冻结解冻业务单元选择
  * @param value
  */
  onBusinessUnitChange = (value)=>{
    this.state.freezeOrgParam.value = value;
    this.setState(this.state);
  }

    /**
     * 冻结解冻弹出框 内容
     * @returns {*}
     * update by yufwm 2020-03-13 给 BusiUnitRefer参照添加 固定宽度
     */
    freezeOrgSelect = ()=>{
        let {freezeOrgParam} = this.state,{BusiUnitRefer} =referUrls;
       return(
            <div className="sup-freeze-div" style={{display: 'flex'}}>
                <div style={{display: 'flex',alignItems: 'center'}}>
                    <div className="ncc-hr-font" style={{marginRight: 10,width: 150,'text-align':'right'}}>{this.Lang['10140SUG-000130']}</div>
                </div>
                <div style={{display: 'flex',alignItems: 'center',width:'300px'}}>
                    {window[BusiUnitRefer].default({...freezeOrgParam})}
                </div>
            </div>
       );
    }

  /**********************************main table ↓**********************************/
    /**
     * 主列表 分页区点击事件
     */
    onMainTablePageInfoClick = (props,config,pks)=>{
      let pageInfo = this.props.table.getTablePageInfo(this.state.table.mainTable.id);

      this.setState({pageInfo:pageInfo},()=>{this.onSearch({checagepage:true},this.setTableData)});
    }
    /**
     * 设置查询区默认值
     */
    setSearchAreaOrgDefaultValue = ()=>{
        let envParam = this.state.envParam,indivOrg = this.state.indivOrg;
        //基本信息查询区
        this.props.meta.getMeta()['supplierquery'].items.filter(item=>{
            let data = {value:envParam.pk_org,display:envParam.org_Name};
            (item.attrcode.endsWith("pk_org_assign") || item.attrcode.endsWith("pk_org")) && this.props.search.setSearchValByField('supplierquery',item.attrcode, data);
        })
        this.props.meta.setMeta(this.props.meta.getMeta());
    }
    /**
     * 自定义表格field适配
     * @param metaId
     */
    meta2TableFieldAdapter = (metaId)=>{
        this.props.meta.getMeta()[metaId].items.forEach(item=>{
            item.title = item.label;
            item.dataIndex = item.attrcode;
            item.key = item.attrcode;
            item.width = 100;
        })
    }

  /**
   * 查询列表
   * @param {isClickSearch(是否点击查询按钮),isRefreshList(是否点击刷新按钮),isCardReturn(是否点击返回按钮)}
   * @param callback
   */
  onSearch = ({isClickSearch,isRefreshList,isCardReturn,checagepage}={},callback=()=>{}) => {
    let {queryInfo,table,envParam} = this.state;
    let searchInfo = this.props.search.getQueryInfo(table.search.id,false);
    let {querycondition} = searchInfo;
    //查询前校验
    this.validate({isClickSearch,isRefreshList,isCardReturn,conditions:querycondition.conditions},()=>{
         //获得当前的分页信息
        let pageInfo = this.getPageInfo(!checagepage,this.state.pageInfo || this.props.table.getTablePageInfo(this.state.table.mainTable.id));
        //点击查询按钮==>记录查询条件
        this.recordSearchInfo({isClickSearch,condition:querycondition},()=>{
            //重置查询区查询条件，保证是最新的条件状态,但是只有点击查询按钮时用最新的查询条件去查询
            this.resetQueryCondition(()=>{
                let {queryInfo} = this.state;
                //构造查询参数
                var param  = {
                    formatInfo:{
                        pageInfo:pageInfo,
                        ...Object.assign({},searchInfo,{querycondition:queryInfo})
                    },
                    showOff:!!table.showOff.checked || false,
                    nodeType:this.props.nodeType,
                    pk_curOrg:envParam.pk_org
                };
                //执行查询
                querycondition.conditions.length>0 && this.query({param,isClickSearch,isRefreshList,checagepage},callback)
                this.asyncPageInfo();
            });
        })
    });
  }
  /**
   * 记录查询信息
   */
  recordSearchInfo = ({isClickSearch,condition} = {},callback = ()=>{})=>{
      let {queryInfo} = this.state;
      this.setState({newQueryInfo:condition,queryInfo:isClickSearch?condition:queryInfo},callback);
  }
  /**
   * 查询前校验
   */
  validate = ({isClickSearch,isRefreshList,isCardReturn,conditions}={},callback=()=>{})=>{
      //只获取查询条件
      if(isRefreshList && (!conditions || conditions.length == 0)){
          toast({title:this.Lang['10140SUG-000200'],color:'success'})/* 国际化处理： 刷新成功！*/
          return;
      }
      if(!conditions || conditions.length == 0){
          return;
      }
      callback();
  }
  /**
   * 获得列表分页信息
   */
  getPageInfo = (flag,info)=>{
      let pageInfo = {
          pageIndex:flag?0:info.pageIndex,
          pageSize:info.pageSize || 10
      }
      return pageInfo;
  }
  /**
   * 同步列表分页信息
   */
  asyncPageInfo = (callback=()=>{})=>{
      let {pageInfo,table} = this.state;
      let newPageInfo = this.props.table.getTablePageInfo(table.mainTable.id);
      if(pageInfo && parseInt(pageInfo.pageIndex)!=parseInt(newPageInfo.pageIndex) && parseInt(pageInfo.pageSize)!=parseInt(newPageInfo.pageSize)){
          this.setState({pageInfo:newPageInfo},callback);
      }
  }
  //同步查询条件
  asyncQueryCondition = (isAsync,callback = ()=>{})=>{
      let {newQueryInfo,queryInfo} = this.state;
      this.setState({queryInfo:isAsync?newQueryInfo:queryInfo},()=>{
          callback();
      });
  }
  /**
   * 重置查询条件
   * @param needReset 是否需要重置
   * @param callback 执行列表查询方法
   *
   */
  resetQueryCondition = (callback = ()=>{})=>{
      let {newQueryInfo,table} = this.state;
      //NCCLOUD-170132  当列表查询区必输项为空时，卡片界面点击返回按钮报错，故添加判断条件
      if(newQueryInfo && newQueryInfo.conditions){
          //设置查询条件
          this.props.search.setSearchValue(table.search.id,newQueryInfo.conditions);
          setTimeout(()=>{
              callback();
          },0);
      }
  }
  /**
   * 主列表查询
   */
  query = ({param,isClickSearch,isRefreshList,checagepage}={},callback = ()=>{})=>{
      if(isClickSearch||isRefreshList||checagepage){
          ajax({
              url:this.state.table.search.url,
              data:param,
              success:(res)=>{
                  //显示公式设置
                  showFormulaSetting.call(this,res,{[this.state.table.mainTable.id]:'simpleTable'});
                  res.success && this.setState({allpks:res.data?res.data['supplier_baseInfo'].allpks:[]},()=>{
                      callback(res.data,setMainTablePageButton.bind(this,false),isClickSearch,isRefreshList);
                  });
              }
          });
      }

  }

  /**
   * 设置主列表数据
   * @param data
   * @param callback
   */
  setTableData =(data,callback,isClickSearch,isRefreshList)=>{
    if(data&&data.supplier_baseInfo){
        cacheTools.set('allpks',data.supplier_baseInfo.allpks);
    }

    this.props.table.setAllTableData(this.state.table.mainTable.id,!!data?data[this.state.table.mainTable.id]:{rows:[]});
    this.setState({queryRecords:!!data?data[this.state.table.mainTable.id].rows:[]},()=>{
        this.props.button.setButtonDisabled(['Print','Menu_Output','Output'],!(data && data[this.state.table.mainTable.id].rows.length>0));
        if(isClickSearch){//是点击查询按钮
            if(data && data[this.state.table.mainTable.id] && data[this.state.table.mainTable.id].allpks.length>0){
                toast({title:`${this.Lang['10140SUG-000132']}${data[this.state.table.mainTable.id].allpks.length}${this.Lang["ibanlang-000017"]}`,color:'success'});/* 国际化处理： 查询成功，共 ${} 条*/
            }else{
                toast({title:this.Lang['10140SUG-000066'],color:'warning'})/* 国际化处理： 未查询出符合条件的数据*/
            }
        }
        isRefreshList && toast({title:this.Lang['10140SUG-000200'],color:'success'})/* 国际化处理： 刷新成功！*/
        setMainTablePageButton.call(this,false);
    })
  }

    /**
     * 主列表按钮点击事件
     * @param props
     * @param id
     */
    onMainTableButtonClick = (props,id)=>{
        onMainTableButtonClick.call(this,props,id);
    }

    /**
     * 主列表行点击事件
     * @param props
     * @param moduleId
     * @param record
     * @param index
     */
    onMainTableRecordClick = (props, moduleId, record, index)=>{
        this.props.button.setButtonVisible('CreateCust',!record['iscustomer'].value);
    }
    /**
     * 主列表操作列按钮点击事件
     * @param record
     * @param index
     * @param props
     * @param key
     */
    onMainTableOprBtnClick = (record,index, props, key)=>{
        onMainTableOprButtonClick.call(this,record,index, props, key);
    }
    /**
     * 主列表行checked事件
     * @param callback
     * @param props
     * @param moduleId
     * @param record
     */
    onMainTableChecked = (callback,props, moduleId, record,index, status)=>{
        let checkedRows = props.table.getCheckedRows(moduleId);//获得选中行集合
        this.setState({selectedRecords:checkedRows},()=>{
            if(!status && (!checkedRows ||checkedRows.length==0)){
                callback && callback('cancel');
                this.disabledEnableButtons('cancel');
            }else{
                let row = checkedRows.find(row=>{
                    return row.data && row.data.values && row.data.values['supstate'].value == '1'
                })
                let enableRow = checkedRows.find(row=>{
                    return row.data && row.data.values && row.data.values['enablestate'].value == '2'
                })
                callback && callback(!!row);
                this.disabledEnableButtons(!!enableRow);
            }
            setMainTablePageButton.call(this,false);
        })
    }
    /**
     * 设置停启用按钮的禁用状态
     * @param flag
     */
    disabledEnableButtons = (flag)=>{
        if(flag=='cancel'){
            this.props.button.setButtonDisabled({Disable:false,Enable:false});
        }else{
            this.props.button.setButtonDisabled({Disable:!flag,Enable:!!flag});
        }
    }
    /**
     * 是否禁用核准按钮
     * @param flag
     */
    disabledApproveButtons = (flag)=>{
        if(flag=='cancel'){
            this.props.button.setButtonDisabled({UnApprove:false,Approve:false});

        }else{
            this.props.button.setButtonDisabled({UnApprove:!flag,Approve:!!flag});
        }
    }
    displayEnablestate = (flag)=>{
        let {selectedRecords} = this.state;
        let record = selectedRecords[0].values?selectedRecords[0].values:selectedRecords[0];
        let data = record.data?record.data.values:record;
        this.props.button.setButtonVisible({
            Card_Enable:!!data['pk_supplier'].value?!flag:false,
            Card_Disable:!!data['pk_supplier'].value?flag:false
        });
    }
    displayApproveButtons = (flag,addCancel) =>{
        let {selectedRecords} = this.state;
        let record = selectedRecords[0].values?selectedRecords[0].values:selectedRecords[0];
        let data = record.data?record.data.values:record;
        this.props.button.setButtonVisible({
            Card_Approve:!!data['pk_supplier'].value?!flag:false,
            Card_UnApprove:!!data['pk_supplier'].value?flag:false
        });
    }
    /**
     * 主表格行双击事件
     * @param record
     * @param index
     * @param props
     * @param e
     */
    onMainTableDoubleClick = (record,index, props, e)=>{
        this.props.cardPagination.setCardPaginationId({id:record['pk_supplier'].value,status:1});
        this.props.pushTo(this.props.pushCardUrl, {
            status: 'browse',
            appcode: pageTo.getAppCode(),
            pagecode: this.props.pagecodecard,
            idx: record['pk_supplier'].value,
            id: record['pk_supplier'].value,
        });
    }
    onMainTableSelectedAll = (props, moduleId, status, length)=>{
        setMainTablePageButton.call(this,false);
    }

    /**
     * 由于业务单元节点  向导批改带有查询组织 向导分配不带查询组织，所以这里做一下适配
     */
    setOrgAssignToCache = ()=>{
        if(this.props.nodeType == 'ORG_NODE'){
            let assignSearchItems = this.props.meta.getMeta()['assignsupplierquery'].items;
            if(assignSearchItems[0].attrcode == 'pk_org_assign'){
                this.state.orgAssignCacheField = assignSearchItems[0];
                assignSearchItems.splice(0,1);
                this.setState(this.state,()=>{
                    this.props.meta.setMeta(this.props.meta.getMeta());
                });
            }
        }
    }

  /* ↓↓↓↓↓↓↓=================================================================联系人组织权限处理逻辑===========================================================↓↓↓↓↓↓↓↓↓*/

  assignOrg= async (phone)=>{
    let { ncmodal } = this.props;
    let {show } = ncmodal;
    const data = await queryorg.call(this, phone);
    if(data == "error") return ;
    this.setState({
      leftTree:data.leftTree,
      rightTree:data.rightTree,
      curPhone:phone
    },() => {
        show('SubjectOrgModal');
    })
  }


        /**
     * 删除移动用户的组织权限
     */
    deletePromptBox = (org)=>{
        promptBox({
            color: 'warning',
            title: this.Lang['10140SUG-000071'],/* 国际化处理： 确认删除*/
            content: this.Lang['10140SUG-000072'],/* 国际化处理： 您确认要删除所选数据么？*/
            beSureBtnClick: this.deleteOrg(org)
        });
    }

    /**
     * 删除移动用户的组织权限
     */
    deleteOrg = (org)=>{
        let phone = this.props.form.getFormItemsValue("linkman",'cell').value;
        console.log('phone====',phone);
        let _this = this;
        ajax({
            url:'/nccloud/baseapp/mobile/orgdelete.do',
            data:{
              phone:phone,
              org:org
            },
            async: false,
            success : (res) => {
                toast({content:this.Lang['10140SUG-000073'],color:'success'});
                _this.refreshOrg();
            },
            error: (msg) => {
                toast({content:msg.message,color:'danger'});
            }
        })
    }

  /**
   * 删除移动用户的组织权限
   */
  deleteOrg = async (org)=>{
      let phone = this.props.form.getFormItemsValue("linkman",'cell').value;
      const data = await delOrg.call(this, {phone, org});
      if(data == "error") return ;
      this.refreshOrg();
  }

   /**
     * 刷新组织权限
     */
  refreshOrg = () => {
    let phone = this.props.form.getFormItemsValue("linkman",'cell').value;
    ajax({
        url: '/nccloud/baseapp/mobile/orgsgrid.do',
        data: {
            phone: phone,
            type: 1
        },
        async: false,
        success: (res) => {
            if(res.data==undefined){
                this.props.table.setAllTableData("SubjectOrg",{rows: []});
                return;
            }
            this.props.table.setAllTableData("SubjectOrg", res.data.SubjectOrg);
        },
        error: (msg) => {
            toast({ content: msg.message, color: 'danger' });
        }
    });
  }

    /**
     * 卡片form编辑后事件
     */
    onAfterCardFormEditEvent =(props, moduleId, key, value, index)=>{
        switch(key){
            case 'innerprofitcenter':
                if(value.value==true){
                    props.form.setFormItemsDisabled(moduleId,{'pk_profitcenter':false});
                    props.form.setFormItemsRequired(moduleId, { 'pk_profitcenter':true});
                }else{
                    props.form.setFormItemsDisabled(moduleId,{'pk_profitcenter':true});
                    props.form.setFormItemsRequired(moduleId, { 'pk_profitcenter':false});
                    props.form.setFormItemsValue(moduleId,{'pk_profitcenter':{value:'',display:''}});
                }
                break;
            case 'supprop':
                /**
                 * 内部单位时，财务组织项可以编辑
                 */
                updateFormItemDisable.call(this,{
                    areaId:constProp.SUP_BASE_CARD,
                    data:{'pk_financeorg':!(value.value=='1'),'isfreecust':value.value=='1'}
                },()=>{
                    updateFormItemRequire.call(this,{
                        areaId:constProp.SUP_BASE_CARD,
                        data:{'pk_financeorg':value.value=='1'}
                    },()=>{
                        //外部单位 清空 财务组织的值
                        !(value.value == '1') && this.props.form.setFormItemsValue(constProp.SUP_BASE_CARD,{'pk_financeorg':{}});
                        value.value == '1' && this.props.form.setFormItemsValue(constProp.SUP_BASE_CARD,{'isfreecust':{}});
                    })
                });
                break;
            case 'pk_org':
                let formData = this.props.form.getAllFormValue(moduleId);
                if(value){
                    let pk_org = value.value;
                    let meta = this.props.meta.getMeta();
                    meta['supplier_baseInfo_card'].items.map(item=>{
                        if(item.attrcode === 'pk_supplierclass'){
                            item.queryCondition = {
                                pk_org : pk_org
                            }
                        }
                    });
                    props.meta.setMeta(meta);
                }

                /**
                 * 业务单元节点 所属组织参照编辑后 重置卡片信息
                 * 如果有编码规则，带出编码
                 */
                if(this.props.nodeType == 'ORG_NODE' && (!formData.rows[0].values['code'].value || formData.rows[0].values['code'].value.length == 0)){
                    this.state.envParam.pk_org = value.value;
                    this.setState(this.state,()=>{
                        this.initPageData(this.setCardValue,this.setCardStatus);
                    })
                }
                break;
            case 'pk_supplier_main'://编辑后事件
            this.state.supplierMain.code = value.refcode || value.code;
            this.state.supplierMain.name = value.refname||value.display;
            this.setState(this.state);
            // value && value.value && ajax({
            //     url:'/nccloud/uapbd/supplier/supplierMainChange.do',
            //     data:{pk_supplier:value.value,refcode:value.refcode || value.code,refname:value.refname||value.display}})
            break;

        }
    }
    /**
     * 供应商联系人表格编辑前事件
     */
    onSupLinkmanTableBeforeEdit = (props, moduleId, key, value,  index, record,status)=>{
        //只有'是否默认'字段 允许编辑
        return key == 'isdefault';
    }
    /**
     * 卡片form按钮事件
     * @param props
     * @param id
     */
    onCardButtonClick = (props,id)=>{
        onCardButtonClick.call(this,props,id)
    }
    /**
     * 表格行双击事件
     * @param moduleId
     * @param props
     * @param record
     * @param index
     */
    onRowDoubleClick = (moduleId,status,props, record, index)=>{
        if(this.state.status == 'add' || this.state.status == 'edit'){
            //卡片编辑态，聚合关系子表不能操作
            return;
        }
        this.setState({dblClkRecord:record},()=>{
            let param = {
                dialogTitle:moduleId == constProp.FINANCE?this.Lang['10140SUG-000112']:this.Lang['10140SUG-000113'],/* 国际化处理： 财务信息,采购信息*/
                dialogWidth:'50%',
                dialogHeight:'60%',
                dialogZIndex:'100',
                showFooter:false,//显示底部按钮区
                showDefaultBtn:false,//显示默认按钮
                listener:{
                    renderContentArea: renderContentArea.bind(this,moduleId),
                    onAfterShow:
                        moduleId==constProp.FINANCE?
                        this.onFinanceDialogAfterShow.bind(this,setFinanceCardBtnStatus.bind(this),null,status?status:statusProp.BROWSE):
                        this.onStockDialogAfterShow.bind(this,setFinanceCardBtnStatus.bind(this),null,status?status:statusProp.BROWSE),
                    onBeforeCancelClick:(callback)=>{querySupFinanceOrStockTableData.call(this,moduleId,true);callback && callback();},
                    onAfterCancelClick:this.onAfterDialogClose,
                }
            };
            setFinanceAndStockReferCondition.call(this,moduleId==constProp.FINANCE?'supfinance_card':'supstock_card',record.hasOwnProperty('data')?record.data.values:record.values);
            this.setState({openDialog:true},()=>{
                this.Dialog.showDialog(Object.assign(param,{Lang:this.Lang}));
            })
        });
    }
    onFinanceOrPurchaseTableSelected = (tableId,props, moduleId, record, index, status)=>{
        this.setFinanceOrPurchaseTableButton(tableId);
    }
    onFinanceOrPurchaseTableSelectedAll = (tableId,props, moduleId, status, length)=>{
        this.setFinanceOrPurchaseTableButton(tableId);
    }
    setFinanceOrPurchaseTableButton = (tableId)=>{
        let selectedRecords = this.props.cardTable.getCheckedRows(tableId);
        // let flag = tableId =='finance'?(selectedRecords.length>1?false:(selectedRecords[0].data.values['payfreezeflag'].value == true ? true:false)):true;
        //debugger;
        this.props.button.setButtonDisabled({
            Finance_Table_Delete:!(tableId == 'finance' && selectedRecords && selectedRecords.length>0),
            Finance_Table_PayFreeze:tableId =='finance'?(selectedRecords.length>1?false:(selectedRecords[0] ? (selectedRecords[0].data.values['payfreezeflag'].value == true ? true:false):true)):true,
            Finance_Table_PayUnFreeze:tableId =='finance'?(selectedRecords.length>1?false:(selectedRecords[0] && selectedRecords[0].data.values['payfreezeflag'].value == true?false:true)):true,
            Finance_Table_TicketFreeze:tableId =='finance'?(selectedRecords.length>1?false:(selectedRecords[0] ? (selectedRecords[0].data.values['makeoutfreezeflag'].value == true ? true:false):true)):true,
            Finance_Table_TicketUnFreeze:tableId =='finance'?(selectedRecords.length>1?false:(selectedRecords[0] && selectedRecords[0].data.values['makeoutfreezeflag'].value == true?false:true)):true,
            Stock_Table_Delete:!(tableId == 'purchase' && selectedRecords && selectedRecords.length>0),
            Stock_Table_OrderFreeze:tableId =='purchase'?(selectedRecords.length>1?false:(selectedRecords[0] ? (selectedRecords[0].data.values['orderfreezeflag'].value == true ? true:false):true)):true,
            Stock_Table_OrderUnFreeze:tableId =='purchase'?(selectedRecords.length>1?false:(selectedRecords[0] && selectedRecords[0].data.values['orderfreezeflag'].value == true?false:true)):true
        });
    }
    /**
     * 财务信息 采购信息 编辑卡片渲染内容
     * @param moduleId
     * @returns {*}
    */
  queryHasAssignOrgContent = ()=>{
      return (<QueryHasAssignOrg {...Object.assign(this.props,{selectedRecords:this.state.selectedRecords},{Lang:this.Lang,inlt:this.inlt})} ref={(HasAssignOrg)=>{this.HasAssignOrg = HasAssignOrg;}}/>)
  }

  /**
     * 冻结解冻窗口关闭回调事件
     */
    onFreezeDialogClose = async (callback)=>{
        let param = getCurParam.call(this,'pk_supplier');
        let orgs = (this.state.freezeOrgParam && this.state.freezeOrgParam.value && this.state.freezeOrgParam.value.length>0)?this.state.freezeOrgParam.value.map(org=>{
            return org.refpk;
        }):[];

        const data = Object.assign(
            param,
            {freezeOrgs:orgs},
            {freeze:this.state.otherParam.freeze},
            {nodeType:this.props.nodeType,pk_curOrg:this.state.envParam.pk_org});
        const resDa = await freezeSupplier.call(this, data);
        if(resDa == "error") return ;

        this.state.freezeOrgParam.value = {};
        this.setState(this.state,()=>{
            //回调中关闭窗口
            callback && callback();
            toast({title:this.state.otherParam.freeze?this.Lang['10140SUG-000150']:this.Lang['10140SUG-000151'],color:'success'});/* 国际化处理： 冻结成功！,解冻成功！*/
        })
    }
    /**
     * dialog关闭后事件
     */
    onAfterDialogClose = (callback)=>{
        this.setState({openDialog:false},callback);
    }

      /**
     * 执行打印
     * @param url
     * @param nodeKey
     * @param pks
     */
    executePrint = ({isPrint,url,nodeKey,pks,isMainPrint}={})=>{
        !!isPrint?
            print('pdf',url,
                {
                    funcode:pageTo.getAppCode(),
                    appcode:pageTo.getAppCode(),
                    nodekey:nodeKey,
                    oids:pks}
                ):
        output({data: {
                funcode:pageTo.getAppCode(),
                nodekey:nodeKey,
                oids: pks,
                outputType: "output"
            }, url: url});
    }

     /**
     * 批改完成事件
     * @param callback
     * update by yufwm 2020-03-17 url 编写错误 修改
     */
    onBatchUpdateFinish = async (callback = ()=>{})=>{
        let param = this.BatchUpdateComp.getBatchUpdateData();
        if(!param) return ;
        let res = await quickBatchUpdate(param);
        if(res == "error") return ;
        //批改后刷新表单或表格
        this.onSearch({checagepage:true},this.setTableData);
        //批改后清空批改信息
        this.BatchUpdateComp.cleanBatchUpdateData();
        //批改后关闭批改弹窗
        callback && callback();
        res.success && toast({title:this.Lang['10140SUG-000161'],color:'success'});/* 国际化处理： 批改成功！,批改成功*/
    }

        /**
     * 批改弹出框取消事件
     */
    onBatchUpdateCancelClick = (callback)=>{
        this.BatchUpdateComp.cleanBatchUpdateData(callback);
    }

     /**
     * 分配 内容
     * @returns {*}
     */
    assignContent = ()=>{
        return(<OrgSelect {...Object.assign(this.props,{Lang:this.Lang,inlt:this.inlt})} ref={( item )=> this.orgSelect = item}/>)
    }

     /**
     * 供应商分配确定前事件
     * @param callback
     */
    onSupFastAssignBeforeSureClick = (callback)=>{
        this.assignSupplier(true,callback);
    }
    /**
     * 供应商取消分配确定前事件
     * @param callback
     */
    onSupFastCancelAssignBeforeSureClick = (callback)=>{
        this.assignSupplier(false,callback);
    }
    /**
     * 分配供应商
     * @param assign
     * @param callback
     */
    assignSupplier = (assign,callback)=>{
        let targetOrgs = this.orgSelect.getData();
        let param = getCurParam.call(this,'pk_supplier');
        targetOrgs?ajax({
            url:assign?Urls.assignUrl:Urls.cancelAssignUrl,
            data:Object.assign(param,{targetIds:targetOrgs},{isFastAssign:true}),
            success:(res)=>{
                this.orgSelect.clearData();//清空分配的数据
                res.success && toast({content:assign?this.Lang['10140SUG-000023']:this.Lang['10140SUG-000133'],color:'success'});/* 国际化处理： 分配成功！,取消分配成功！*/
                res.success && callback && callback(res);
            }
        }):toast({content:this.Lang['10140SUG-000134'],color:'warning'});/* 国际化处理： 没有指定操作的目标组织！*/
    }
     /**
     * 生成客户弹窗内容
     */
    createCustContent = ()=>{
        return createCustContent.call(this);
    }
    /**
     * 生成客户确认按钮点击前 事件
     */
    onCreateCustSureBtnClick = (callback,destroyHotKeys)=>{
        onCreateCustSureBtnClick.call(this, callback, destroyHotKeys);
    }
    /**
     * 生成客户取消按钮点击事件
     * @param callback
     */
    onCreateCustCancelBtnClick = (callback,destroyHotKeys)=>{
        onCreateCustCancelBtnClick.call(this, callback, destroyHotKeys);
    }
    /**
     * 生成客户弹窗关闭后事件
     */
    onAfterCreateCustClose = ()=>{
        onAfterCreateCustClose.call(this);
    }

    /**
     * 创建 关联客户内容
     * @returns {*}
     */
    associateCustContent = ()=>{
        return associateCustContent.call(this);
    }
    /**
     * 关联客户确认按钮点击事件
     */
    onAssociateCustSureClick = (callback,destroyHotKeys)=>{
        onAssociateCustSureClick.call(this, callback,destroyHotKeys);
    }
    /**
     *  关联客户取消按钮 点击事件
     */
    onAssociateCustCancelBtnClick = (callback,destroyHotKeys)=>{
        onAssociateCustCancelBtnClick.call(this, callback, destroyHotKeys);
    }
    /**
     * 关联客户确认时 提示框中确认按钮点击事件
     */
    onAssociateCustPrompSureBtnClick = (callback,destroyHotKeys)=>{
        onAssociateCustPrompSureBtnClick.call(this, callback, destroyHotKeys);
    }

    onMainTableOperateDelClick = (isAsyncDel) => {
        onMainTableOperateDelClick.call(this, isAsyncDel);
    }

    /**
     * 按组织查看 弹出框内容
     * @returns {*}
     */
    orgBrowseContent = ()=>{
        return(<div style={{width:'100%'}}><SupOrgBrowse {...Object.assign(this.props,{Lang:this.Lang,inlt:this.inlt})} ref={(SupOrgBrowse)=>{this.SupOrgBrowse = SupOrgBrowse;}}/></div>)
    }
    /**
     * 按组织查看关闭窗口时 清空数据
     */
    clearOrgBrowseData = (callback)=>{
        this.SupOrgBrowse.initOrgBrowsePage(callback);
    }

    canCreateVersion=()=>{
        let _this = this;
        validateAddOrCopy.call(this,()=>{
            ajax({
                url: '/nccloud/uapbd/supplier/supplierCanCreateVersion.do',
                data: {pk_supplier:_this.state.pk_supplier},
                async: false,
                success: (result) => {
                    confirmUtil.call(this, {
                        title: this.Lang['10140SUG-000077'], /* 国际化处理： 询问*/
                        content: this.Lang['10140SUG-000249'],//"创建新版本后，当前版本将变为历史版本且不可修改、删除。是否创建新版本？"
                        beSureBtnClick: () => {
                            _this.props.modal.close('createVersion');
                            _this.saveVersionInfo();
                        }
                    })
                },
                error: (msg) => {
                    _this.props.modal.close('createVersion');
                    toast({ content: msg.message, color: 'danger' });
                }
            });
        })

    }

    saveVersionInfo = () => {
        let {pushCardUrl} = this.props;
        this.createSupplierVersion( () => {
            this.props.pushTo(pushCardUrl, {
                'idx': this.state.pk_supplier,
                id: this.state.pk_supplier,
                'version':this.props.form.getAllFormValue("versionList_card").rows[0].values.version.value,
                'begindate':this.props.form.getAllFormValue("versionList_card").rows[0].values.begindate.value,
                status: 'edit',
                appcode: pageTo.getAppCode(),
                pagecode: this.props.pagecodecard
            });
        })
    }

    createSupplierVersion = (call) => {
        let reqParams = {
            'version':this.props.form.getAllFormValue("versionList_card").rows[0].values.version.value,
            'begindate':this.props.form.getAllFormValue("versionList_card").rows[0].values.begindate.value,
            'pk_supplier':this.state.pk_supplier,
        }
        ajax({
            url: "/nccloud/uapbd/supplier/suplierCreateVersion.do",
            data: reqParams,
            success: (res) => {
                const {success, data} = res;
                toast({color: 'success', title: this.Lang['10140SUG-000250']});/*版本化成功*/
                setTimeout( () => {
                    call && call();
                }, 1000)

            }
        })
    }

    render() {
        return(
        <div>
            {draw.call(this)}
        </div>
        )
    }
}

/*AyflEomXWyqCHfdTxzWda1f37E6BmbYMFlQ4qgWlYuq3WYvveC97Qm1zYJR3TbDu*/
